#include <stdio.h>
#include <stdlib.h>


void callatz(int number, int *key);
void sort(int size, int *array);

int main(int argc, char *argv[]) {
  int i, j, size;
  int *array;

  scanf("%d", &size);
  array = (int *)malloc(sizeof(int) * size);

  for (i = 0; i < size; i++) {
    scanf("%d", array + i);
  }

  for (i = 0; i < size; i++) {
    for (j = 0; j < size; j++) {
      if (i != j) callatz(array[i], (array + j));
    }
  }

  sort(size, array);

  for (i = 0; i < size; i++) {
    if (array[i] != 0) {
      printf("%d", array[i]);
      if (i + 1 == size || array[i + 1] == 0)
        printf("\n");
      else
        printf(" ");
    }
  }

  return 0;
}


void callatz(int number, int *key) {
  while (number != 1 && number != 0) {
    if (*key == number) {
      *key = 0;
      break;
    }
    number = number % 2 == 0 ? number / 2 : (number * 3 + 1) / 2;
  }
}


void sort(int size, int *array) {
  int i, j, tmp;
  for (i = 1; i < size; i++) {
    j = i - 1;
    tmp = *(array + i);
    while (tmp > *(array + j) && j >= 0) {
      *(array + j + 1) = *(array + j);
      j--;
    }
    *(array + j + 1) = tmp;
  }
}
